﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Microsoft.Practices.Mobile.ContainerModel;

namespace Microsoft.Practices.Unity
{
	public class UnityContainer : IUnityContainer
	{
        public static IUnityContainer Instance { get; set; }

		private readonly Container _container = new Container();

        public Dictionary<Type, object> ServiceTypes { get { return _container.ServiceTypes; } }

        public UnityContainer()
        {
            _container.RegisterInstance<IUnityContainer>(this);
            if (Instance == null)
                Instance = this;
        }

		public void BuildUp(object classBase)
		{
		    _container.BuildUp(classBase);
		}

        public T1 Resolve<T1>()
        {
            return _container.Resolve<T1>();
        }

        public IUnityContainer RegisterInstance(Type t, string name, object instance, LifetimeManager lifetime)
        {
            return _container.RegisterInstance(t, name, instance, lifetime);
        }

        public object Resolve(Type t, string name, params ResolverOverride[] resolverOverrides)
        {
            return _container.ResolveType(t);
        }

        public object BuildUp(Type t, object existing, string name, params ResolverOverride[] resolverOverrides)
        {
            return _container.BuildUp(t, existing, name, resolverOverrides);
        }

        public IUnityContainer AddExtension(UnityContainerExtension extension)
        {
            return _container.AddExtension(extension);
        }

        public IUnityContainer Parent
        {
            get { return _container.Parent; }
        }

        public void Dispose()
        {
            _container.Dispose();
        }

        public object ResolveType(Type service)
        {
            return _container.ResolveType(service);
        }

        public void Teardown(object o)
        {
            _container.Teardown(o);
        }

        public IUnityContainer RegisterType(Type from, Type to, string name, LifetimeManager lifetimeManager, params InjectionMember[] injectionMembers)
        {
            return _container.RegisterType(from, to, name, lifetimeManager, injectionMembers);
        }

        public IEnumerable<object> ResolveAll(Type t, params ResolverOverride[] resolverOverrides)
        {
            return _container.ResolveAll(t, resolverOverrides);
        }

        public object Configure(Type configurationInterface)
        {
            return _container.Configure(configurationInterface);
        }

        public IUnityContainer RemoveAllExtensions()
        {
            return _container.RemoveAllExtensions();
        }


        public IUnityContainer CreateChildContainer()
        {
            return _container.CreateChildContainer();
        }

        public IEnumerable<ContainerRegistration> Registrations
        {
            get { return _container.Registrations; }
        }

    }
}
